package cn.itcast.jobs;

import cn.itcast.massage.RedisConstant;
import cn.itcast.utils.QiniuUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import redis.clients.jedis.JedisPool;

import java.util.Set;

@Component
public class JobDemo {
    // 注入jedis连接池对象
    @Autowired
    private JedisPool jedisPool;

    public void clearPic(){
        // 求两个set的差集
        Set<String> set = jedisPool.getResource().sdiff(RedisConstant.SETMEAL_PIC_RESOURCES, RedisConstant.SETMEAL_PIC_DB_RESOURCES);
        // 遍历set,删除差集在jedis和七牛云的数据
        for (String pic : set) {
            jedisPool.getResource().srem(RedisConstant.SETMEAL_PIC_RESOURCES,pic);
            QiniuUtils.deleteFileFromQiniu(pic);
            System.out.println("自定义任务执行，清理垃圾图片:" + pic);
        }
    }
}
